var t = getApp(), e = require("../../utils/data.js");

Page({
    data: {
        colors: [ "red", "orange", "yellow", "green", "purple" ],
        banner_url: e.getBannerData(),
        indicatorDots: !0,
        vertical: !1,
        autoplay: !0,
        interval: 3e3,
        duration: 1e3,
        class_num: null,
        curNavId: 1,
        curIndex: 0,
        hiddenmodalput: !0,
        szMention: null
    },
    onLoad: function() {
        wx.login({
            success: function(t) {
                t.code ? wx.request({
                    url: e.getInterfaceData() + "onkey.action",
                    data: {
                        code: t.code,
                        stunum: wx.getStorageSync("person_uname")
                    }
                }) : console.log("登录失败！" + t.errMsg);
            }
        }), wx.request({
            url: e.getInterfaceData() + "mainpageinfo.action",
            data: {
                person_uname: wx.getStorageSync("person_uname")
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                1 == t.data.typeinfo && wx.showModal({
                    title: t.data.title,
                    showCancel: !1,
                    content: t.data.content
                });
            }
        });
        var n = this;
        try {
            var a = wx.getStorageSync("username"), o = wx.getStorageSync("personid"), s = wx.getStorageSync("person_uname"), c = wx.getStorageSync("persontype");
            console.log(a), t.appData.userinfo = {
                username: a,
                personid: o,
                person_uname: s,
                persontype: c
            }, console.log(a), this.setData({
                type: c
            }), a ? (18 == c ? ((n = this).setData({
                myTitle: "课程信息"
            }), console.log(t.appData.userinfo.person_uname), wx.request({
                url: e.getInterfaceData() + "stuclassinfor.action",
                data: {
                    person_uname: t.appData.userinfo.person_uname
                },
                header: {
                    "content-type": "application/json"
                },
                success: function(t) {
                    n.setData({
                        list: t.data
                    }), console.log(t.data);
                }
            })) : ((n = this).setData({
                myTitle: "教学任务"
            }), console.log(t.appData.userinfo.person_uname), wx.request({
                url: e.getInterfaceData() + "mstatusinfor.action",
                data: {
                    person_uname: t.appData.userinfo.person_uname
                },
                header: {
                    "content-type": "application/json"
                },
                success: function(t) {
                    n.setData({
                        list: t.data
                    }), console.log(t.data);
                }
            })), console.log("13213")) : wx.redirectTo({
                url: "../login/login"
            });
        } catch (t) {}
        var i = wx.getUpdateManager();
        i.onCheckForUpdate(function(t) {
            console.log(1.6), console.log(t.hasUpdate);
        }), i.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(t) {
                    t.confirm && i.applyUpdate();
                }
            });
        }), i.onUpdateFailed(function() {});
    },
    szMentionInput: function(t) {
        console.log(t.detail.value), this.setData({
            szMention: t.detail.value
        });
    },
    onShow: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.userLocation"] || wx.authorize({
                    scope: "scope.userLocation",
                    success: function() {}
                });
            }
        });
        var t = wx.getUpdateManager();
        t.onCheckForUpdate(function(t) {
            console.log(1.6), console.log(t.hasUpdate);
        }), t.onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(e) {
                    e.confirm && t.applyUpdate();
                }
            });
        }), t.onUpdateFailed(function() {});
    },
    onReady: function() {},
    againDvBtnClick: function() {
        this.setData({
            myTitle: "地理位置",
            list: null
        }), this.mapCtx = wx.createMapContext("myMap"), this.mapCtx.moveToLocation();
    },
    tclassBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "mstatusinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "教学任务"
                }), console.log(t.data);
            }
        });
    },
    navigateDetail: function(t) {
        try {
            wx.setStorageSync("cnum", t.currentTarget.dataset.aid);
        } catch (t) {}
        wx.navigateTo({
            url: "../detail/detail?artype=" + t.currentTarget.dataset.aid
        });
    },
    cqinforDetail: function(t) {
        wx.navigateTo({
            url: "../stuminfor/stuminfor?artype=" + t.currentTarget.dataset.aid
        });
    },
    szqdDetail: function(t) {
        this.setData({
            hiddenmodalput: !this.data.hiddenmodalput,
            sjsvalue: ""
        });
        try {
            wx.setStorageSync("cnum", t.currentTarget.dataset.aid), wx.setStorageSync("tid", t.currentTarget.dataset.tid);
        } catch (t) {}
    },
    cancel: function() {
        this.setData({
            hiddenmodalput: !0,
            szMention: null
        });
    },
    confirm: function() {
        var t = wx.getStorageSync("cnum"), n = this.data.szMention, a = wx.getStorageSync("personid"), o = wx.getStorageSync("tid");
        console.log(this.data.szMention), this.setData({
            hiddenmodalput: !0,
            szMention: null
        }), wx.request({
            url: e.getInterfaceData() + "fdqmention.action",
            data: {
                cnum: t + "-" + o + "-" + n,
                pid: a,
                location: "暂无地理位置"
            },
            header: {
                "content-type": "application/json"
            },
            success: function(n) {
                if (console.log(n.data), -2 == n.data && wx.showModal({
                    title: "考勤失败",
                    showCancel: !1,
                    content: "您的设备有多位同学登陆信息，为确保考勤结果准确，系统不允许您进行签到，请提醒其他用户在自己的设备进行登录，确保您的设备只登陆您的学号",
                    success: function(t) {
                        t.confirm && console.log("用户点击确定");
                    }
                }), -1 == n.data || 0 == n.data) wx.showModal({
                    title: "考勤失败",
                    showCancel: !1,
                    content: "随机数无效",
                    success: function(t) {
                        t.confirm && console.log("用户点击确定");
                    }
                }); else {
                    var o = n.data[0].class_teacher, s = n.data[0].class_name;
                    wx.showModal({
                        title: "考勤成功",
                        showCancel: !1,
                        confirmText: "获取位置",
                        content: "您已完成" + o + "老师授课的" + s + "的考勤。为确保考勤有效，i重科将采集您所处的经纬度信息。由于手机性能原因，采集速度可能有所不同，请确保GPS状态正常。",
                        success: function(n) {
                            n.confirm && (console.log("用户点击确定"), wx.getLocation({
                                type: "wgs84",
                                success: function(n) {
                                    var o = n.latitude, s = n.longitude;
                                    n.speed, n.accuracy;
                                    wx.showModal({
                                        title: "地理位置获取成功",
                                        showCancel: !1,
                                        content: "您当前所处位置:纬度:" + o + "经度:" + s,
                                        confirmText: "立即上传",
                                        success: function(n) {
                                            n.confirm && wx.request({
                                                url: e.getInterfaceData() + "updatelocation.action",
                                                data: {
                                                    cnum: t,
                                                    pid: a,
                                                    location: "纬度:" + o + "经度:" + s
                                                },
                                                header: {
                                                    "content-type": "application/json"
                                                },
                                                success: function(t) {
                                                    console.log(t.data), wx.showModal({
                                                        title: "上传成功",
                                                        showCancel: !1,
                                                        content: "您已成功上传地理位置",
                                                        success: function(t) {
                                                            t.confirm && console.log("用户点击确定");
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    });
                                }
                            }));
                        }
                    });
                }
            }
        });
    },
    statusChange: function(t) {
        this.setData({
            class_num: t.currentTarget.dataset.aid
        });
        var n = t.detail.value, a = this.data.class_num;
        console.log(n), console.log(a), 0 == (n = 1 == n ? 0 : -1) && wx.showModal({
            title: "重要提示",
            content: "【考勤即将开始】请首先让学生们做好签到准备，学生准备完毕后，点击立即开始，正式开始考勤。\r\n【请注意】建议将考勤时间控制在20秒左右，防止学生进行代签",
            confirmText: "立即开始",
            showCancel: !1,
            success: function(t) {
                t.confirm && wx.request({
                    url: e.getInterfaceData() + "changestatus.action",
                    data: {
                        cnum: a,
                        p_num: wx.getStorageSync("person_uname"),
                        status: n
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function(t) {
                        0 == n && "1" != t.data ? wx.showModal({
                            title: "数字签到模式",
                            content: "【考勤已开始】请将随机数" + t.data + "告知同学，考勤完毕后请及时关闭考勤开关。",
                            confirmText: "我已知晓",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && console.log("用户点击确定");
                            }
                        }) : 0 == n && "1" == t.data ? wx.showModal({
                            title: "扫码签到模式",
                            content: "【考勤已开始】请展示考勤二维码，考勤完毕后请及时关闭考勤开关。\r\n【请注意】考勤二维码从网页端进行获取，访问地址：\r\nhttp://jwc.cqust.edu.cn/iCqust。",
                            confirmText: "我已知晓",
                            showCancel: !1,
                            success: function(t) {
                                t.confirm && console.log("用户点击确定");
                            }
                        }) : wx.showToast({
                            icon: "success",
                            title: "修改成功"
                        }), console.log(t.data);
                    }
                });
            }
        }), -1 == n && wx.request({
            url: e.getInterfaceData() + "changestatus.action",
            data: {
                cnum: a,
                p_num: wx.getStorageSync("person_uname"),
                status: n
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                wx.request({
                    url: e.getInterfaceData() + "findlastminfor.action",
                    data: {
                        cnum: a,
                        p_num: wx.getStorageSync("person_uname")
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function(t) {
                        wx.showModal({
                            title: "考勤结果",
                            content: "【考勤已结束】" + t.data,
                            confirmText: "保留",
                            cancelText: "删除",
                            showCancel: !0,
                            success: function(t) {
                                t.confirm && (console.log("保留"), wx.showModal({
                                    title: "考勤结果",
                                    content: "考勤结果已生成，请在考勤信息中查看。",
                                    confirmText: "我已知晓",
                                    showCancel: !1,
                                    success: function(t) {
                                        t.confirm;
                                    }
                                })), t.cancel && (console.log("删除"), wx.request({
                                    url: e.getInterfaceData() + "deletelastminfor.action",
                                    data: {
                                        cnum: a,
                                        p_num: wx.getStorageSync("person_uname")
                                    },
                                    header: {
                                        "content-type": "application/json"
                                    },
                                    success: function(t) {
                                        "OK" == t.data && wx.showModal({
                                            title: "重要提示",
                                            content: "已经删除本次考勤结果。",
                                            confirmText: "我已知晓",
                                            showCancel: !1,
                                            success: function(t) {
                                                t.confirm;
                                            }
                                        }), console.log(t.data);
                                    }
                                }));
                            }
                        });
                    }
                });
            }
        });
    },
    mclassBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "mstatusinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "考勤信息"
                }), console.log(t.data);
            }
        });
    },
    mStatusBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "mstatusinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "考勤开关"
                }), console.log(t.data);
            }
        });
    },
    sminforListtBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "stuclassinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "出勤信息"
                }), console.log(t.data);
            }
        });
    },
    sclassListBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "stuclassinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "课程信息"
                }), console.log(t.data);
            }
        });
    },
    szMentionBtnClick: function() {
        var n = this;
        console.log(t.appData.userinfo.person_uname), wx.request({
            url: e.getInterfaceData() + "stuclassinfor.action",
            data: {
                person_uname: t.appData.userinfo.person_uname
            },
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                n.setData({
                    list: t.data,
                    myTitle: "数字签到"
                }), console.log(t.data);
            }
        });
    },
    scanBtnClick: function() {
        wx.scanCode({
            onlyFromCamera: !0,
            success: function(n) {
                console.log(n);
                var a = t.appData.userinfo.personid, o = n.result;
                wx.request({
                    url: e.getInterfaceData() + "fdqmention.action",
                    data: {
                        cnum: o,
                        pid: a,
                        location: "暂无地理位置"
                    },
                    header: {
                        "content-type": "application/json"
                    },
                    success: function(t) {
                        if (console.log(t.data), -2 == t.data && wx.showModal({
                            title: "考勤失败",
                            showCancel: !1,
                            content: "您的设备有多位同学登陆信息，为确保考勤结果准确，系统不允许您进行签到，请提醒其他用户在自己的设备进行登录，确保您的设备只登陆您的学号",
                            success: function(t) {
                                t.confirm && console.log("用户点击确定");
                            }
                        }), -1 == t.data || 0 == t.data) wx.showModal({
                            title: "考勤失败",
                            showCancel: !1,
                            content: "考勤二维码无效",
                            success: function(t) {
                                t.confirm && console.log("用户点击确定");
                            }
                        }); else {
                            var n = t.data[0].class_teacher, s = t.data[0].class_name;
                            wx.showModal({
                                title: "考勤成功",
                                showCancel: !1,
                                confirmText: "获取位置",
                                content: "您已完成" + n + "老师授课的" + s + "的考勤。为确保考勤有效，i重科将采集您所处的经纬度信息。由于手机性能原因，采集速度可能有所不同，请确保GPS状态正常。",
                                success: function(t) {
                                    t.confirm && (console.log("用户点击确定"), wx.getLocation({
                                        type: "wgs84",
                                        success: function(t) {
                                            var n = t.latitude, s = t.longitude;
                                            t.speed, t.accuracy;
                                            wx.showModal({
                                                title: "地理位置获取成功",
                                                showCancel: !1,
                                                content: "您当前所处位置:纬度:" + n + "经度:" + s,
                                                confirmText: "立即上传",
                                                success: function(t) {
                                                    t.confirm && wx.request({
                                                        url: e.getInterfaceData() + "updatelocation.action",
                                                        data: {
                                                            cnum: o,
                                                            pid: a,
                                                            location: "纬度:" + n + "经度:" + s
                                                        },
                                                        header: {
                                                            "content-type": "application/json"
                                                        },
                                                        success: function(t) {
                                                            console.log(t.data), wx.showModal({
                                                                title: "上传成功",
                                                                showCancel: !1,
                                                                content: "您已成功上传地理位置",
                                                                success: function(t) {
                                                                    t.confirm && console.log("用户点击确定");
                                                                }
                                                            });
                                                        }
                                                    });
                                                }
                                            });
                                        }
                                    }));
                                }
                            });
                        }
                    }
                });
            }
        });
    }
});